package vip.xiaonuo.core.config;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 墨塵
 * @since 2023/2/20
 */
@Slf4j
@Component
public class AuthRunner implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        long startTime = System.currentTimeMillis();
        log.info("系统启动清除在线人员----start");
        List<String> sessionListB = StpUtil.searchSessionId("", -1, -1, true);
        for(String session:sessionListB){
            String userId = StrUtil.split(session, StrUtil.COLON).get(3);
            StpUtil.kickout(userId);
        }
        log.info("系统启动清除在线人员{"+sessionListB.size()+"}----end,耗时:" + (System.currentTimeMillis() - startTime) + "ms");
    }
}
